package com.talkweb.newproject.admin.controller;

import com.talkweb.newproject.admin.rest.SysRoleMappingRest;
import com.talkweb.newproject.admin.sysrolemapping.dto.SysRoleMappingDTO;
import com.talkweb.newproject.api.model.admin.SysRoleMappingParam;
import com.talkweb.newproject.api.model.common.ResponseResult;
import com.talkweb.newproject.api.model.common.Status;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.xml.crypto.dsig.spec.ExcC14NParameterSpec;
import java.util.List;

/**
 * Created by qsf on 2019/5/14.
 */
@RestController
@RequestMapping(value="/sysRoleMapping-api")
@Slf4j
@Api(tags = {"角色映射管理接口"})
public class SysRoleMappingController {
    @Autowired
    private SysRoleMappingRest sysRoleMappingRest;

    @ResponseBody
    @RequestMapping(value="/getSysRoleMappingById",method = RequestMethod.POST)
    public ResponseResult<SysRoleMappingDTO> querySysRoleMappingByPrimaryKey(@PathVariable("ID") String ID) throws Exception {
        ResponseResult<SysRoleMappingDTO> result = new ResponseResult<>();
        try{
            return sysRoleMappingRest.querySysRoleMappingByPrimaryKey(ID);

        }catch(Exception e) {
            log.error(e.getMessage(),e);
            result.setStatus(Status.FAILD);
            result.setMessage("执行异常,请重试");
            return result;
        }
    }

    @ResponseBody
    @RequestMapping(value="/querySysRoleMappingList",method = RequestMethod.POST)
    public ResponseResult<Object> querySysRoleMappingList(@RequestBody SysRoleMappingParam obj) throws Exception {
        ResponseResult<Object> result = new ResponseResult<>();
        try{

            Object list = sysRoleMappingRest.querySysRoleMappingList(obj);
            result.setData(list);
            return result;
        }catch(Exception e) {
            log.error(e.getMessage(),e);
            result.setStatus(Status.FAILD);
            result.setMessage("执行异常,请重试");
            return result;
        }

    }

    @ResponseBody
    @RequestMapping(value="/Web/queryLike",method = RequestMethod.POST)
    public ResponseResult<SysRoleMappingDTO> queryLike(@RequestBody SysRoleMappingDTO obj) throws Exception {
        ResponseResult<SysRoleMappingDTO> result = new ResponseResult<>();
        try{

            return sysRoleMappingRest.queryLike(obj);
        }catch(Exception e) {
            log.error(e.getMessage(),e);
            result.setStatus(Status.FAILD);
            result.setMessage("执行异常,请重试");
            return result;
        }

    }

    /**
     * 新增数据
     * @param obj
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping(value="/add",method = RequestMethod.POST)
    public ResponseResult insertSysRoleMapping(@RequestBody SysRoleMappingDTO obj) throws Exception {
        ResponseResult result = new ResponseResult();
        try{

            return sysRoleMappingRest.create(obj);
        }catch(Exception e) {
            log.error(e.getMessage(),e);
            result.setStatus(Status.FAILD);
            result.setMessage("执行异常,请重试");
            return result;
        }
    }

    @ResponseBody
    @RequestMapping(value="/updateSysRoleMapping",method = RequestMethod.POST)
    public ResponseResult updateSysRoleMapping(@RequestBody SysRoleMappingDTO obj) throws Exception {
        ResponseResult result = new ResponseResult();
        try{

            return sysRoleMappingRest.update(obj);
        }catch(Exception e) {
            log.error(e.getMessage(),e);
            result.setStatus(Status.FAILD);
            result.setMessage("执行异常,请重试");
            return result;
        }
    }

    @ResponseBody
    @RequestMapping(value="/deleteSysRoleMapping",method = RequestMethod.POST)
    public ResponseResult deleteSysRoleMapping(@RequestParam("ids") String ids) throws Exception {
        ResponseResult result = new ResponseResult();
        try{

            return sysRoleMappingRest.deleteSysRoleMapping(ids);
        }catch(Exception e) {
            log.error(e.getMessage(),e);
            result.setStatus(Status.FAILD);
            result.setMessage("执行异常,请重试");
            return result;
        }
    }
}
